/*
 * Copyright (C) 2011 CrystalRange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.crystalrange;

import java.util.ArrayList;

public abstract class MenuTreeNode {

    ArrayList<MenuTreeNode> children = null;

    public abstract void readChildren();

    public ArrayList<MenuTreeNode> getChildren() {
        return this.children;
    }

    public MenuTreeNode getChild(int index) {
        MenuTreeNode child = null;

        if (this.children == null) {
            this.readChildren();
        }

        if (this.children != null && (index > -1 && index < this.children.size())) {
            child = this.children.get(index);
        }

        return child;
    }

    public int getChildCount() {
        int size = 0;

        if (this.children == null) {
            this.readChildren();
        }

        if (this.children != null) {
            size = this.children.size();
        }

        return size;
    }

    public abstract boolean isLeaf();
}
